package com.mypage.view.activity.beautMore;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.manager.UrlManager;
import com.cloudcc.mobile.util.UserUtils;
import com.cloudcc.mobile.view.activity.BeauInfoActivity;
import com.cloudcc.mobile.view.activity.NewContactDetails;
import com.cloudcc.mobile.view.activity.NewUserInfoActivity;
import com.cloudcc.mobile.view.base.BaseActivity;
import com.lidroid.xutils.BitmapUtils;
import com.mypage.utils.AnimViewUtils;
import com.mypage.utils.ImageLoaderUtils_circle;
import com.mypage.utils.SaveTemporaryData;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GroupPdetailActivity extends BaseActivity {
    public String url = UrlManager.getInterfaceUrl() + "?binding=" + RunTimeManager.getInstance().getServerBinding() + "&serviceName=showChatterImage&type=user&id=";
    private String mEns = RunTimeManager.getInstance().getlanguage();
    public static GroupPdetailActivity instance = null;
    @Bind(R.id.imgLeftBack)
    ImageView imgLeftBack;
    @Bind(R.id.textTitle)
    TextView textTitle;
    @Bind(R.id.inTextLine)
    TextView inTextLine;
    @Bind(R.id.btnEdit)
    Button btnEdit;
    @Bind(R.id.deleteBtn)
    Button deleteBtn;
    @Bind(R.id.coustomName)
    TextView coustomName;
    @Bind(R.id.createPerson)
    TextView createPerson;
    @Bind(R.id.createPersonName)
    TextView createPersonName;
    @Bind(R.id.createTime)
    TextView createTime;
    @Bind(R.id.changeName)
    TextView changeName;
    @Bind(R.id.roleName)
    TextView roleName;
    @Bind(R.id.textQuanxian)
    TextView textQuanxian;
    @Bind(R.id.imgHeader)
    ImageView imgHeader;

    @Bind(R.id.toastHintContent)
    TextView toastHintContent;
    @Bind(R.id.imgDeletes)
    ImageView imgDeletes;
    @Bind(R.id.topLayoutBackg)
    RelativeLayout topLayoutBackg;
    @Bind(R.id.layoutTop)
    FrameLayout layoutTop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_group_pdetail);
        ButterKnife.bind(this);
        instance = this;
        initView();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_group_pdetail;
    }

    public void initView() {
        BitmapUtils bitmapUtils = new BitmapUtils(this);
        if ("en".equals(mEns)) {

            inTextLine.setText("User");
            textTitle.setText("Business Opportunity Group members");
        } else {
            inTextLine.setText("用户");
            textTitle.setText("业务机会小组成员");
        }


        coustomName.setText(getIntent().getStringExtra("mName"));
        roleName.setText(getIntent().getStringExtra("mZhiWei"));
        textQuanxian.setText(getIntent().getStringExtra("mQuanXian"));

        createPersonName.setText(getIntent().getStringExtra("mCreate"));//创建人
        String time = getFormatTime(getIntent().getStringExtra("mCreateTime"));
        createTime.setText("   ,   " + time);//创建时间
        changeName.setText(getIntent().getStringExtra("mAppor"));//业务机会

        ImageLoader.getInstance().displayImage(url + getIntent().getStringExtra("mUserid"), imgHeader, ImageLoaderUtils_circle.MyDisplayImageOptions());
    }

    @OnClick({R.id.btnEdit, R.id.deleteBtn, R.id.imgLeftBack, R.id.createPersonName, R.id.changeName})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.imgLeftBack:
                finish();
                break;
            case R.id.btnEdit:
                Intent intent = new Intent(this, EditGroupActivity.class);
                intent.putExtra("mCreate", getIntent().getStringExtra("mName"));//创建人改成了用户
                intent.putExtra("mCreateTime", createTime.getText().toString());//创建时间
                intent.putExtra("mAppor", changeName.getText().toString());//业务机会
                intent.putExtra("mQuanXian", textQuanxian.getText().toString());//权限
                intent.putExtra("mZhiWei", roleName.getText().toString());//职位


                intent.putExtra("mOpportunity", getIntent().getStringExtra("mOpportunity"));
                intent.putExtra("mCreateId", getIntent().getStringExtra("mCreateId"));

                intent.putExtra("mUserid", getIntent().getStringExtra("mUserid"));
                intent.putExtra("mId", getIntent().getStringExtra("mId"));


                startActivity(intent);
//                startActivityForResult(intent, 0);
                break;
            case R.id.deleteBtn:
                Intent intent1 = new Intent(this, DeleteGroupActivity.class);
                intent1.putExtra("mId", getIntent().getStringExtra("mId"));
                startActivity(intent1);
                break;
            case R.id.createPersonName://创建人
                Intent Intent = new Intent(this, NewUserInfoActivity.class);

                Intent.putExtra("userId", getIntent().getStringExtra("mCreateId"));
                startActivity(Intent);

                break;
            case R.id.changeName://业务机会
                Intent s = new Intent(this, BeauInfoActivity.class);
                s.putExtra("web", getIntent().getStringExtra("mOpportunity"));
                s.putExtra("beau.nameid", "opportunity");
                startActivity(s);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data == null) {
            return;
        } else {
            roleName.setText(data.getStringExtra("roleName"));
            textQuanxian.setText(data.getStringExtra("quanName"));
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    public String getFormatTime(String time) {
        String Hour;
        String year = time.substring(0, 10) + " ";//YYYY-MM-Dd
        String shi = time.substring(10, time.length() - 6).toString().trim();
        String minute = time.substring(14, time.length() - 3);
        int data = Integer.valueOf(shi) - 12;
        if (data > 0) {
            Hour = year + "下午 " + String.valueOf(data) + ":" + minute;
        } else {
            Hour = year + "上午 " + shi + ":" + minute;
        }

        return Hour;
    }

    @Override
    protected void onResume() {
        if ("no".equals(SaveTemporaryData.mIsnet)) {
            setToast();
        }
        super.onResume();
    }

    @Override
    protected void onPause() {
        SaveTemporaryData.mIsnet = "qqq";
        super.onPause();
    }

    public void setToast() {
        layoutTop.setVisibility(View.VISIBLE);
        topLayoutBackg.setVisibility(View.GONE);
        toastHintContent.setText(R.string.meg_net_no);
        new AnimViewUtils().appearToast(topLayoutBackg);
    }

    @OnClick(R.id.imgDeletes)
    public void onClick() {
        layoutTop.setVisibility(View.GONE);
    }
}
